package com.ag.zhh.service;

import com.ag.bean.TbEvent;
import com.ag.bean.TbEventStatus;
import com.ag.dao.TbEventDAO;
import com.ag.dao.TbEventStatusDAO;
import com.ag.wzp.dao.WzpTbEventDAO;

public class EventStatusService {
	
public static String EVENT_STATUS_SJJB = "1001";//事件接报
	
	public static String EVENT_STATUS_SJSHL = "1002";//事件受理
	
	public static String EVENT_STATUS_YJCHP_ING = "1003";//一级呈批中
	
	public static String EVENT_STATUS_YJCHP_FINISH = "1004";//一级呈批完成
	
	public static String EVENT_STATUS_ERJCHP_ING = "1005";//二级呈批中
	
	public static String EVENT_STATUS_ERJCHP_FINISH = "1006";//二级呈批完成
	
	public static String EVENT_STATUS_SJCHP_ING = "1007";//三级呈批中
	
	public static String EVENT_STATUS_SJCHP_FINISH = "1008";//三级呈批完成
	
	public static String EVENT_STATUS_YJSHQ_ING = "1009";//应急申请中
	
	public static String EVENT_STATUS_YJSHQSHL = "1010";//应急申请受理
	
	public static String EVENT_STATUS_YJPZH = "1011";//应急批准
	
	public static String EVENT_STATUS_YJSHH = "1012";//应急审核
	
	public static String EVENT_STATUS_SJDDZHH = "1013";//事件等待指挥
	
	public static String EVENT_STATUS_SJZHHSL = "1014";//事件指挥受理
	
	public static String EVENT_STATUS_SJCHZH_ING = "1015";//事件处置中
	
	public static String EVENT_STATUS_SJCHZH_FINISH = "1016";//事件处置结束
	
	public static String EVENT_STATUS_SJBJ = "1017";//事件办结
	
	public static String EVENT_STATUS_SJGD = "1018";//事件归档
	
	/**
	 * 更改事件状态 
	 * @param statusId 查看静态字段
	 * @param eventId 更改的事件ID
	 * @return 返回事件对象
	 */
	public TbEvent changeTbEventStatus(String statusId,String eventId) {
		TbEvent event = eventDAO.findById(eventId);
		if(event == null) {
			throw new RuntimeException("EventStatusService：changeTbEventStatus() 事件不存在");
		}
		TbEventStatus newEventStatus = new TbEventStatus();
		newEventStatus.setTbesId(statusId);
//		newEventStatus = eventStatusDAO.merge(newEventStatus);
//		if(newEventStatus == null) {
//			throw new RuntimeException("EventStatusService：changeTbEventStatus() 事件状态ID不存在");
//		}
		event.setTbEventStatus(newEventStatus);
		eventDAO.attachDirty(event);
		//System.out.println("EventStatusService :changeTbEventStatus()---"+event.getTbEventStatus().getTbesId());
		return event;
	}
	
	public boolean checkEventStatus(String statusId,String eventId) {
		TbEvent event = eventDAO.findById(eventId);
		if(event == null) {
			throw new RuntimeException("EventStatusService：changeTbEventStatus() 事件不存在");
		}
		return event.getTbEventStatus().getTbesId().equals(statusId);
	}
	
	private TbEventStatusDAO eventStatusDAO;
	
	private WzpTbEventDAO eventDAO;
	
	public TbEventStatusDAO getEventStatusDAO() {
		return eventStatusDAO;
	}

	public void setEventStatusDAO(TbEventStatusDAO eventStatusDAO) {
		this.eventStatusDAO = eventStatusDAO;
	}

	public EventStatusService() {
		// TODO Auto-generated constructor stub
	}

	public WzpTbEventDAO getEventDAO() {
		return eventDAO;
	}

	public void setEventDAO(WzpTbEventDAO eventDAO) {
		this.eventDAO = eventDAO;
	}


	
	
}
